package io.renren.controller;

import io.renren.entity.AccidentInsuranceManagementEntity;
import io.renren.entity.SysUserEntity;
import io.renren.service.AccidentInsuranceManagementService;
import io.renren.utils.PageUtils;
import io.renren.utils.QueryAuthority;
import io.renren.utils.R;
import io.renren.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 意外险享受管理
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-11 11:56:34
 */
@RestController
@RequestMapping("accidentinsurancemanagement")
public class AccidentInsuranceManagementController {
	@Autowired
	private AccidentInsuranceManagementService accidentInsuranceManagementService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("accidentinsurancemanagement:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        QueryAuthority query = new QueryAuthority(params);

		List<AccidentInsuranceManagementEntity> accidentInsuranceManagementList = accidentInsuranceManagementService.queryList(query);
		int total = accidentInsuranceManagementService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(accidentInsuranceManagementList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("accidentinsurancemanagement:info")
	public R info(@PathVariable("id") Integer id){
		AccidentInsuranceManagementEntity accidentInsuranceManagement = accidentInsuranceManagementService.queryObject(id);
		
		return R.ok().put("accidentInsuranceManagement", accidentInsuranceManagement);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("accidentinsurancemanagement:save")
	public R save(@RequestBody AccidentInsuranceManagementEntity accidentInsuranceManagement){
		SysUserEntity user= (SysUserEntity) ShiroUtils.getSubject().getSession().getAttribute("user");
		accidentInsuranceManagement.setCusername(user.getUsername());
		accidentInsuranceManagement.setCdate(new Date());
		accidentInsuranceManagement.setCdeptId(user.getDeptNo());
		accidentInsuranceManagementService.save(accidentInsuranceManagement);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("accidentinsurancemanagement:update")
	public R update(@RequestBody AccidentInsuranceManagementEntity accidentInsuranceManagement){
		accidentInsuranceManagementService.update(accidentInsuranceManagement);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("accidentinsurancemanagement:delete")
	public R delete(@RequestBody Integer[] ids){
		accidentInsuranceManagementService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
